/**   
 * Copyright © 2018 Navatics. All rights reserved.
 * 
 * @Title: CreateCodeUtil.java 
 * @Prject: appserver
 * @Package: com.navatics.util
 * @Description: TODO
 * @author: Run.Tong   
 * @email: run.tong@navatics.com
 * @date: 2018年7月2日 下午4:50:12
 * @version: V1.0   
 */
package com.lopo.util;

import java.util.Random;

/**
 * @ClassName: CreateCodeUtil
 * @Description: TODO 生成随机验证码
 */
public class CreateCodeUtil {
	/**
	 * @Title: getRandomNumCode
	 * @Description: TODO 生成数字验证码
	 * @param number 位数
	 * @return
	 * @return: String
	 */
	public static String getRandomNumCode(int number) {
		String codeNum = "";
		int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		Random random = new Random();
		for (int i = 0; i < number; i++) {
			int next = random.nextInt(10000);// 目的是产生足够随机的数，避免产生的数字重复率高的问题
			codeNum += numbers[next % 10];
		}
		return codeNum;
	}
	/**
	 * @Title: getRandomCode
	 * @Description: TODO 生成随机码值，包含数字、大小写字母
	 * @param number 位数
	 * @return
	 * @return: String
	 */
	public static String getRandomComCode(int number) {
		String codeNum = "";
		int[] code = new int[3];
		Random random = new Random();
		for (int i = 0; i < number; i++) {
			int num = random.nextInt(10) + 48;
			int uppercase = random.nextInt(26) + 65;
			int lowercase = random.nextInt(26) + 97;
			code[0] = num;
			code[1] = uppercase;
			code[2] = lowercase;
			codeNum += (char) code[random.nextInt(3)];
		}
		return codeNum;
	}
	
	/**
	 * 
	 * @Title: getCompleteCode 
	 * @Description: TODO   获取完整的codeKey
	 * @param email 		用户邮箱
	 * @param codeSuffix	code的前缀
	 * @param type			发送邮件的类型
	 * @return
	 * @return: String
	 */
	public static String getCompleteCodeKey(String email, String codeSuffix, String type) {
		return email + codeSuffix + "_" + type;
	}
	
	/**
	 * @Title: main
	 * @Description: TODO have a test
	 * @param args
	 * @return: void
	 */
	public static void main(String[] args) {
//		System.out.println(getRandomNumCode(4));
		for (int i = 0; i < 10; i++) {
			System.out.println(getRandomComCode(5));
		}
	}
}
